package com.groupsix.service.impl;

import com.groupsix.entity.Stgrade;
import com.groupsix.mapper.StgradeMapper;
import com.groupsix.mapper.StudentMapper;
import com.groupsix.service.StgradeService;
import com.groupsix.utils.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 董盛昌
 * @Title: ${file_name}
 * @Package ${package_name}
 * @Description: 学生卫生业务逻辑接口实现类
 * @date 2021/10/17 22:53
 */
@Service
public class StgradeServiceImpl implements StgradeService {


    @Autowired
    private StgradeMapper stgradeMapper;


    //分页查询
    @Override
    public PageInfo findPageInfo(Integer sStudentid, String sName, Integer sDormitoryid, Integer pageIndex, Integer pageSize) {
        PageInfo pi = new PageInfo();
        pi.setPageIndex(pageIndex);
        pi.setPageSize(pageSize);
        //获取总条数
        Integer totalCount = stgradeMapper.totalCount(sStudentid,sName,sDormitoryid);
        if (totalCount>0){
            pi.setTotalCount(totalCount);
            //每一页显示宿舍信息数
            //currentPage = (pageIndex-1)*pageSize  当前页码数减1*最大条数=开始行数
            List<Stgrade> studentCleanList = stgradeMapper.getStgradeList(sStudentid,sName,sDormitoryid,
                    (pi.getPageIndex()-1)*pi.getPageSize(),pi.getPageSize());
            pi.setList(studentCleanList);
        }
        return pi;
    }

    @Override
    public List<Stgrade> getAll(){
        List<Stgrade> stgradeList = stgradeMapper.getAll();
        return stgradeList;
    }

    //添加宿舍卫生信息
    @Override
    public int addStgrade(Stgrade stgrade) {
        return stgradeMapper.addStgrade(stgrade);
    }

    //通过id删除宿舍卫生信息
    @Override
    public int deleteStgrade(Integer gId) {
        return stgradeMapper.deleteStgrade(gId);
    }

    //修改宿舍卫生信息
    @Override
    public int updateStgrade(Stgrade stgrade) {
        return stgradeMapper.updateStgrade(stgrade);
    }

    @Override
    public Stgrade findStgradeById (Integer gId){
        Stgrade d = stgradeMapper.findStgradeById(gId);
        return  d;
    }
}
